package com.client;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TcpClient {
	public static void main(String[] args) throws UnknownHostException, IOException {

		Socket sc = new Socket("127.0.0.1", 8888);

		BufferedReader readInConsole = new BufferedReader(new InputStreamReader(System.in));

		OutputStream out = sc.getOutputStream();

		BufferedReader reader = new BufferedReader(new InputStreamReader(sc.getInputStream()));

		while (true) {
			String line = reader.readLine();
			System.out.println(line);

			String command = readInConsole.readLine();

			if (command.endsWith("Q")) {
				out.write("bye\n".getBytes());
				break;
			}

			out.write((command + "\n").getBytes());

		}
		reader.close();
		out.close();
		sc.close();

	}

	public void quit(OutputStream out) throws IOException {
		out.write("bye\n".getBytes());
	}

}
